

var dtime = '_deadtime';

	


function put(k, v, t) {

  uni.setStorageSync(k, v)

  var seconds = parseInt(t);

  if (seconds > 0) {

    var timestamp = Date.parse(new Date());

    timestamp = timestamp / 1000 + seconds;

    uni.setStorageSync(k + dtime, timestamp + "")

  } else {
    uni.removeStorageSync(k + dtime)
  }

}

 

function get(k) {

  var deadtime = parseInt(uni.getStorageSync(k + dtime))
	
  if (deadtime) {
    if (parseInt(deadtime) < Date.parse(new Date()) / 1000) {
		remove(k);
		return false;
    }
  }

  var res = uni.getStorageSync(k);
  if (res) {
    return res;
  } 
	remove(k);
	return false;
}

 

function remove(k) {
  uni.removeStorageSync(k);
  uni.removeStorageSync(k + dtime);
}

function clear() {
  uni.clearStorageSync();
}

 

module.exports = {

  put: put,

  get: get,

  remove: remove,

  clear: clear,

}
